﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtility;
using CommonFunc;

public partial class Control_ProductList_Small : System.Web.UI.UserControl
{
    MODEL.ProductClass MPC = new MODEL.ProductClass();
    MODEL.ProductClass _MPC = new MODEL.ProductClass();

    BLL.ProductClass BPC = new BLL.ProductClass();


    #region 封装字段
    private int topNum;
    private int classID;
    private string filterExpression;
    private int subStrNum;
    private bool isIndex;

    public int TopNum
    {
        get { return topNum; }
        set { topNum = value; }
    }

    public int ClassID
    {
        get { return classID; }
        set { classID = value; }
    }

    public string FilterExpression
    {
        get { return filterExpression; }
        set { filterExpression = value; }
    }

    public int SubStrNum
    {
        get { return subStrNum; }
        set { subStrNum = value; }
    }

    public bool IsIndex
    {
        get { return isIndex; }
        set { isIndex = value; }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
	    ControlDataInit();
    }

    #region ControlDataInit
    protected void ControlDataInit()
    {
        try
        {
            string SQLstr_Product;

            if (this.TopNum != 0)
            {
                SQLstr_Product = "SELECT TOP " + this.TopNum + " * FROM [Product] WHERE [Product_IsLock]=false AND [Product_IsDel]=false ";
            }
            else
            {
                SQLstr_Product = "SELECT * FROM [Product] WHERE [Product_IsLock]=false AND [Product_IsDel]=false ";
            }

            if (this.ClassID != 0)
            {
                MPC.PC_ID = this.ClassID;

                _MPC = BPC.GetDataByID(MPC);

                string ClassCode = _MPC.PC_ClassCode;

                SQLstr_Product += "AND [Product_ClassCode] LIKE '" + ClassCode + "%' ";
            }

            if (this.IsIndex)
            {
                SQLstr_Product += " AND [Product_Index]=true ";
            }

            if (this.FilterExpression != null)
            {
                SQLstr_Product += "AND " + this.FilterExpression;
            }

            SQLstr_Product += " ORDER BY [Product_Order] DESC";

            DataTable DT_Product = AccHelper.GetDataTable(SQLstr_Product);

            DL_ProductList.DataSource = DT_Product.DefaultView;

            DL_ProductList.DataBind();
        }
        catch (Exception ex)
        {
            LB_ProductList_Small.Text = ex.Message;
        }
    }
    #endregion


    #region 格式化文章标题
    protected string FormatProductTitle(object _Title)
    {
        string ProductTitle = Convert.ToString(_Title);

        if (this.SubStrNum == 0)
        {
            return ProductTitle;
        }
        else
        {
            if (ProductTitle.Length > this.SubStrNum)
            {
                return CommonFunction.SubStr(ProductTitle, this.SubStrNum, " …");
            }
            else
            {
                return ProductTitle;
            }
        }
    }
    #endregion
}
